package com.cryptape.cita_wallet.activity.transfer;

import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.cryptape.cita.protocol.core.methods.response.AppSendTransaction;
import com.cryptape.cita_wallet.activity.StimulateExtractActivity;
import com.cryptape.cita_wallet.constant.ConstantUtil;
import com.cryptape.cita_wallet.item.Chain;
import com.cryptape.cita_wallet.item.Currency;
import com.cryptape.cita_wallet.item.Token;
import com.cryptape.cita_wallet.item.Wallet;
import com.cryptape.cita_wallet.item.transaction.AppTransaction;
import com.cryptape.cita_wallet.service.ContractService;
import com.cryptape.cita_wallet.service.http.CITARpcService;
import com.cryptape.cita_wallet.service.http.CytonSubscriber;
import com.cryptape.cita_wallet.service.http.EthRpcService;
import com.cryptape.cita_wallet.service.http.TokenService;
import com.cryptape.cita_wallet.service.http.WalletService;
import com.cryptape.cita_wallet.util.CurrencyUtil;
import com.cryptape.cita_wallet.util.NumberUtil;
import com.cryptape.cita_wallet.util.db.DBWalletUtil;
import com.cryptape.cita_wallet.util.ether.EtherUtil;
import com.mangoworld.android.R;

import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.DynamicArray;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.utils.Numeric;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.Callable;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

import static com.cryptape.cita_wallet.activity.transfer.TransferActivity.EXTRA_ADDRESS;
import static com.cryptape.cita_wallet.activity.transfer.TransferActivity.EXTRA_TOKEN;

/**
 */
public class StimulateExtractPresenter {


    private StimulateExtractActivity mActivity;
    private TransferView mTransferView;

    private Token mToken;
    private double mTokenPrice = 0;
    private Wallet mWallet;
    private Currency mCurrency;

    private BigInteger mGasPrice, mGasLimit, mGas;
    private BigInteger mQuota, mQuotaLimit, mQuotaPrice;
    private String mData;
    private double mTokenBalance, mNativeTokenBalance, mTransferFee;
    public String lockContractAddress;

    public StimulateExtractPresenter(StimulateExtractActivity activity, TransferView transferView) {
        mActivity = activity;
        mTransferView = transferView;

        init();
    }

    public void init() {

        EthRpcService.init(mActivity);
//        CITARpcService.init(mActivity, HttpCITAUrls.CITA_NODE_URL);

        initTokenItem();
        getAddressData();
        initWalletData();
        getTokenBalance();
        initTransferFee();

    }

    private void withdrawIncentive(String password, String value, String receiveAddress) {

            Observable.fromCallable(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    List<Type> datas = ContractService.lockAddress();
                    if (datas != null && datas.size() >= 1) {
                        return ((Address) datas.get(0)).getValue();
                    }
                    return null;
                }
            }).subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<String>() {
                        @Override
                        public void onCompleted() {
//                        mTransferView.transferEtherFail("");
                        }

                        @Override
                        public void onError(Throwable e) {
                            mTransferView.transferEtherFail(e.getMessage());
                        }

                        @Override
                        public void onNext(String s) {
                            if (!TextUtils.isEmpty(s)) {
                                execWithDraw(password,value,s);
//                            lockbalance(password, value, s, decimal, type, s);
                            } else {
                                mTransferView.transferEtherFail("获取地址失败");
                            }
                        }
                    });
        }

    private void execWithDraw(String password, String value, String receiveAddress){
        EthRpcService.withdrawIncentive(mActivity, mToken, receiveAddress, value, mGasPrice, mGasLimit, password)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferEtherFail(e.getMessage());
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }

    public void incentiveDetail() {
        mTransferView.startUpdateEthGasPrice();
        Observable.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                List<Type> datas = ContractService.lockAddress();
                if (datas != null && datas.size() == 1) {
                    return ((Address) datas.get(0)).getValue();
                }
                return null;
            }
        }).flatMap(new Func1<String, Observable< List<Type>>>() {
            @Override
            public Observable<List<Type>> call(String o) {
                return Observable.fromCallable(new Callable<List<Type>>() {
                    @Override
                    public List<Type> call() throws Exception {
                        if(o == null || o.equals("0x0000000000000000000000000000000000000000")){
                            return null;
                        }
                        StimulateExtractPresenter.this.lockContractAddress = o;
                        List<Type> datas = ContractService.incentiveDetail(o);
                        return datas;
                    }
                });
            }}).subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<Type>>() {

                    @Override
                    public void onCompleted() {
                        mTransferView.updateEthGasPriceSuccess(BigInteger.ONE);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mTransferView.updateEthGasPriceSuccess(BigInteger.ONE);
//                        mTransferView.transferEtherFail("获取地址失败");
                    }

                    @Override
                    public void onNext(List<Type> datas) {
                        {
                            if (datas != null && datas.size() > 0) {
                                String type = null;
                                DynamicArray<Uint256> incentives = ((DynamicArray<Uint256>)datas.get(0));
                                if(incentives != null){
                                   List<Uint256> incentiveDatas =  incentives.getValue();
                                   if(incentiveDatas != null && incentiveDatas.size() >=3){
                                       BigInteger currencyIncentive = ((Uint256) incentiveDatas.get(0)).getValue();
                                       BigInteger communityIncentive = ((Uint256) incentiveDatas.get(1)).getValue();
                                       BigInteger nodeIncentive = ((Uint256) incentiveDatas.get(2)).getValue();
                                       mActivity.updateIncentive(currencyIncentive,communityIncentive,nodeIncentive);
                                       initGasLimit();
                                   }
                                }
                            }else{
                                Toast.makeText(mActivity,mActivity.getString(R.string.tip_no_incentives),Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                });
    }

    private void getTokenBalance() {
//        WalletService.getBalanceWithToken(mActivity, mToken).subscribe(new CytonSubscriber<Double>() {
//            @Override
//            public void onNext(Double balance) {
//                mTokenBalance = balance;
//                mTransferView.updateAnyTokenBalance(balance);
//            }
//        });

        WalletService.getBalanceWithNativeToken(mActivity, mToken).subscribe(new Subscriber<Double>() {
            @Override
            public void onNext(Double balance) {
                mNativeTokenBalance = balance;
                mTransferView.updateNativeTokenBalance(balance);
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onCompleted() {

            }
        });

    }

    private void getAddressData() {
        String address = mActivity.getIntent().getStringExtra(EXTRA_ADDRESS);
        mTransferView.updaterReceiveAddress(address);
    }

    private void initTokenItem() {
        mToken = mActivity.getIntent().getParcelableExtra(EXTRA_TOKEN);
//        mTransferView.updateTitleData("闪电兑换");
    }

    private void initWalletData() {
        mWallet = DBWalletUtil.getCurrentWallet(mActivity);
        mTransferView.updateWalletData(mWallet);
    }

    private void initTransferFee() {
        if (EtherUtil.isEther(mToken)) {
            initEthGasInfo();
            mTransferView.initTransferEditValue();
            initTokenPrice();
        } else {
            initCITAQuota();
        }
    }

    private void initEthGasInfo() {
        mGasLimit = EtherUtil.isNative(mToken) ? ConstantUtil.QUOTA_TOKEN : ConstantUtil.QUOTA_ERC20;
        if(mActivity.getClass().getSimpleName().contains("ExchangeActivity")){
            mGasLimit = ConstantUtil.QUOTA_ERC20;
        }else if(mActivity.getClass().getSimpleName().contains("ActivateActivity")){
            mGasLimit = ConstantUtil.QUOTA_ERC20_BIG_1;
            mGasPrice = ConstantUtil.GAS_PRICE_BIG;
        }else if(mActivity.getClass().getSimpleName().contains("StimulateExtractActivity")){
            mGasLimit = ConstantUtil.QUOTA_ERC20_BIG_1;
            mGasPrice = ConstantUtil.GAS_PRICE_BIG;
        }
        mTransferView.startUpdateEthGasPrice();
        EthRpcService.getEthGasPrice().subscribe(new CytonSubscriber<BigInteger>() {
            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                mTransferView.updateEthGasPriceFail(e);
            }

            @Override
            public void onNext(BigInteger gasPrice) {
                mGasPrice = gasPrice;
                updateGasInfo();
                mTransferView.updateEthGasPriceSuccess(gasPrice);
                incentiveDetail();
            }
        });
    }

    /**
     * get the price of token
     */
    private void initTokenPrice() {
        mCurrency = CurrencyUtil.getCurrencyItem(mActivity);
        TokenService.getCurrency(ConstantUtil.ETH, mCurrency.getName())
                .subscribe(new CytonSubscriber<String>() {
                    @Override
                    public void onNext(String price) {
                        if (TextUtils.isEmpty(price))
                            return;
                        try {
                            mTokenPrice = Double.parseDouble(price);
                            mTransferView.initTransferFeeView();
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }


    private void initCITAQuota() {
        mQuotaLimit = TextUtils.isEmpty(getTokenItem().getContractAddress()) ? ConstantUtil.QUOTA_TOKEN : ConstantUtil.QUOTA_ERC20;
        CITARpcService.getQuotaPrice(mWallet.address)
                .subscribe(new CytonSubscriber<String>() {
                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(String quotaPrice) {
                        mQuotaPrice = new BigInteger(quotaPrice);
                        initQuotaFee();
                        mTransferView.initTransferFeeView();
                    }
                });

    }

    private void initQuotaFee() {
        mQuota = mQuotaLimit.multiply(mQuotaPrice);
        mTransferFee = NumberUtil.getEthFromWei(mQuota);
        mTransferView.updateCITAQuota(NumberUtil.getDecimalValid_8(mTransferFee) + getFeeTokenUnit());
    }

    public void updateQuotaLimit(BigInteger quotaLimit) {
        mQuotaLimit = quotaLimit;
        initQuotaFee();
    }

    public BigInteger getQuotaLimit() {
        return mQuotaLimit;
    }

    public void initGasLimit(AppTransaction appTransaction) {
//        EthRpcService.getEthGasLimit(appTransaction)
//                .subscribe(new CytonSubscriber<BigInteger>() {
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                    }
//
//                    @Override
//                    public void onNext(BigInteger gasLimit) {
//                        mGasLimit = gasLimit.multiply(ConstantUtil.GAS_LIMIT_PARAMETER);
//                        updateGasInfo();
//                    }
//                });
    }


    public void initGasLimit() {
        org.web3j.protocol.core.methods.request.Transaction transaction = mActivity.getStimulateExtractTransactionInfo();
        EthRpcService.getEthGasLimit(transaction)
                .subscribe(new CytonSubscriber<BigInteger>() {
                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(BigInteger gasLimit) {
                        Log.e("MainActivity:","getEthGasLimit:"+gasLimit);
//                        mGasLimit = gasLimit.multiply(ConstantUtil.GAS_LIMIT_PARAMETER);
                        if(gasLimit != null) {
                            mGasLimit = new BigDecimal(gasLimit).multiply(new BigDecimal("1.1")).toBigInteger();
//                        mGasLimit = gasLimit.multiply(new BigInteger("11").divide(new BigInteger("10")));
                            Log.e("MainActivity:", "getEthGasLimit mGasLimit:" + mGasLimit);
                            updateGasInfo();
                        }
                    }
                });
    }


    public void handleActiveAction(String password, String transferValue, String receiveAddress,byte[] data) {
        if (EtherUtil.isEther(mToken)) {
//            if (ConstantUtil.ETH.equals(mToken.symbol))
//            {
//                transferEth(password, transferValue, receiveAddress);
//            } else
                {
                transferEthErc777(password, transferValue, receiveAddress,data);
            }
        } else {
            if (isNativeToken()) {
                transferCITAToken(password, transferValue, receiveAddress.toLowerCase());
            } else {
                transferCITAErc20(password, transferValue, receiveAddress.toLowerCase());
            }
        }
    }


    public void handleTransferAction(String password, String transferValue, String receiveAddress) {
        if (EtherUtil.isEther(mToken)) {
            if (ConstantUtil.ETH.equals(mToken.getSymbol())) {
                transferEth(password, transferValue, receiveAddress);
            } else {
                withdrawIncentive(password, transferValue, receiveAddress);
            }
        } else {
            if (isNativeToken()) {
                transferCITAToken(password, transferValue, receiveAddress.toLowerCase());
            } else {
                transferCITAErc20(password, transferValue, receiveAddress.toLowerCase());
            }
        }
    }

    public void handleEntrustTransferAction(String password, String transferValue, String receiveAddress) {
        if (EtherUtil.isEther(mToken)) {
            if (ConstantUtil.ETH.equals(mToken.getSymbol())) {
                transferEth(password, transferValue, receiveAddress);
            } else {
                transferEntrustEthErc20(password, transferValue, receiveAddress);
            }
        } else {
            if (isNativeToken()) {
                transferCITAToken(password, transferValue, receiveAddress.toLowerCase());
            } else {
                transferCITAErc20(password, transferValue, receiveAddress.toLowerCase());
            }
        }
    }

    /**
     * transfer origin token of ethereum
     *
     * @param value
     */
    private void transferEth(String password, String value, String receiveAddress) {
        EthRpcService.transferEth(mActivity, receiveAddress, value, mGasPrice, mGasLimit, mData, password)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferCITAFail(e);
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        Log.e("MainActivity",ethSendTransaction.getTransactionHash());
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }


    /**
     * transfer origin token of ethereum
     *
     * @param value
     */
    private void transferEthErc20(String password, String value, String receiveAddress) {
        EthRpcService.transferErc20(mActivity, mToken, receiveAddress, value, mGasPrice, mGasLimit, password)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferEtherFail(e.getMessage());
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }


//    private void lock(){
//        Observable.fromCallable(new Callable<String>() {
//            @Override
//            public String call() throws Exception {
//                return ContractService.lockNature();
//            }
//        }).subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<String>() {
//            @Override
//            public void onCompleted() {
//
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onNext(String s) {
//                mTransferView.transferEtherSuccess();
//                if (TextUtils.isEmpty(s)) {
////                    mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
//                } else {
////                    mTransferView.transferEtherSuccess(ethSendTransaction);
//                }
//            }
//        });
//    }


    private void lockNature(String password, String value, String receiveAddress) {
        EthRpcService.lockNature(mActivity, mToken, receiveAddress, value, mGasPrice, mGasLimit, password)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferEtherFail(e.getMessage());
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }

//    public static void lockbalance(String type){
//        Subscription subscribe = Observable.interval(5, TimeUnit.SECONDS)
//                .take(15)
//                .map(new Func1<Long, Object>() {
//                    @Override
//                    public Object call(Long aLong) {
//                        ContractService.lockbalance();
//                        return null;
//                    }
//                })
//                .subscribeOn(Schedulers.newThread())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Action1<Object>() {
//                    @Override
//                    public void call(Object o) {
//
//                    }
//                });
//
//    }
//

    private void transferEntrustEthErc20(String password, String value, String receiveAddress) {
//        lockNature(password,value,receiveAddress);

        EthRpcService.transferEntrustErc20(mActivity, mToken, receiveAddress, value, mGasPrice, mGasLimit, password)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferEtherFail(e.getMessage());
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            lockNature(password,value,receiveAddress);
//                            lock();

//                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }


    private void transferEthErc777(String password, String value, String receiveAddress,byte[] data) {
        EthRpcService.transferErc777(mActivity, mToken, receiveAddress, value, mGasPrice, mGasLimit, password,data)
                .subscribe(new CytonSubscriber<EthSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferEtherFail(e.getMessage());
                    }

                    @Override
                    public void onNext(EthSendTransaction ethSendTransaction) {
                        if (ethSendTransaction.hasError()) {
                            mTransferView.transferEtherFail(ethSendTransaction.getError().getMessage());
                        } else {
                            mTransferView.transferEtherSuccess(ethSendTransaction);
                        }
                    }
                });
    }

    /**
     * transfer origin token of nervos
     *
     * @param transferValue transfer value
     */
    private void transferCITAToken(String password, String transferValue, String receiveAddress) {
        Chain item = DBWalletUtil.getChainItemFromCurrentWallet(mActivity, mToken.getChainId());
        if (item == null)
            return;
        CITARpcService.setHttpProvider(item.httpProvider);
        CITARpcService.transferCITA(mActivity, receiveAddress, transferValue, mData, mQuotaLimit.longValue(),
                new BigInteger(mToken.getChainId()), password)
                .subscribe(new CytonSubscriber<AppSendTransaction>() {
                    @Override
                    public void onError(Throwable e) {
                        mTransferView.transferCITAFail(e);
                    }

                    @Override
                    public void onNext(AppSendTransaction appSendTransaction) {
                        mTransferView.transferCITASuccess(appSendTransaction);
                    }
                });
    }


    /**
     * transfer erc20 token of nervos
     *
     * @param transferValue
     */
    private void transferCITAErc20(String password, String transferValue, String receiveAddress) {
        Chain item = DBWalletUtil.getChainItemFromCurrentWallet(mActivity, mToken.getChainId());
        if (item == null)
            return;
        try {
            CITARpcService.transferErc20(mActivity, mToken, receiveAddress, transferValue, mQuotaLimit.longValue(),
                    Numeric.toBigInt(mToken.getChainId()), password)
                    .subscribe(new CytonSubscriber<AppSendTransaction>() {
                        @Override
                        public void onError(Throwable e) {
                            e.printStackTrace();
                            mTransferView.transferCITAFail(e);
                        }

                        @Override
                        public void onNext(AppSendTransaction appSendTransaction) {
                            mTransferView.transferCITASuccess(appSendTransaction);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void updateGasInfo() {
        mGas = mGasPrice.multiply(mGasLimit);
        mTransferFee = NumberUtil.getEthFromWei(mGas);
        mTransferView.initTransferFeeView();
    }

    /**
     * @param gasPrice wei
     */
    public void updateGasPrice(BigInteger gasPrice) {
        mGasPrice = gasPrice;
        updateGasInfo();
    }

    public void updateGasLimit(BigInteger gasLimit) {
        mGasLimit = gasLimit;
        updateGasInfo();
    }

    public void updateData(String data) {
        mData = data;
    }

    public String getData() {
        return mData;
    }

    public Token getTokenItem() {
        return mToken;
    }

    public Wallet getWalletItem() {
        return mWallet;
    }

    public BigInteger getGasLimit() {
        return mGasLimit;
    }

    public boolean isTransferFeeEnough() {
        return mNativeTokenBalance - mTransferFee >= 0;
    }

    /**
     * Check whether transfer value is bigger than balance of wallet
     *
     * @return
     */
    public boolean checkTransferValueMoreBalance(String transferValue) {
        if(TextUtils.isEmpty(transferValue)){
            transferValue = "0";
        }
        if (isNativeToken()) {
            return Double.parseDouble(transferValue) > (mNativeTokenBalance - mTransferFee);
        } else {
            return Double.parseDouble(transferValue) > mTokenBalance;
        }
    }

    public String balanceSubFee() {
        if (isNativeToken()) {
            return NumberUtil.getDecimalValid_8(new BigDecimal(mNativeTokenBalance).subtract(new BigDecimal(mTransferFee)).doubleValue());
        } else {
            return NumberUtil.getDecimalValid_8(mTokenBalance);
        }
    }

    public String getTransferFee() {
        if (mTokenPrice > 0 && EtherUtil.isMainNet()) {
            return NumberUtil.getDecimalValid_8(mTransferFee) + getFeeTokenUnit()
                    + " ≈ " + mCurrency.getSymbol() + " "
                    + NumberUtil.getDecimalValid_2(mTransferFee * mTokenPrice);
        } else {
            return NumberUtil.getDecimalValid_8(mTransferFee) + getFeeTokenUnit();
        }
    }

    public BigInteger getGasPrice() {
        return mGasPrice;
    }

    public boolean isEthERC20() {
        return Numeric.toBigInt(mToken.getChainId()).compareTo(BigInteger.ZERO) < 0
                && !TextUtils.isEmpty(mToken.getContractAddress());
    }

    public boolean isNativeToken() {
        return TextUtils.isEmpty(mToken.getContractAddress());
    }

    public boolean isEther() {
        return Numeric.toBigInt(mToken.getChainId()).compareTo(BigInteger.ZERO) < 0;
    }

    public String getFeeTokenUnit() {
        if (EtherUtil.isEther(mToken)) {
            return " " + ConstantUtil.ETH;
        } else {
            Chain chain = DBWalletUtil.getChainItemFromCurrentWallet(mActivity, mToken.getChainId());
            return chain == null || TextUtils.isEmpty(chain.tokenSymbol) ? "" : " " + chain.tokenSymbol;
        }
    }

}
